package br.com.fafica.sisape.view;

import java.awt.BorderLayout;
import java.awt.EventQueue;

import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.border.EmptyBorder;
import java.awt.Color;
import javax.swing.JLabel;
import java.awt.Font;
import java.util.ArrayList;

import javax.swing.JComboBox;
import javax.swing.JButton;

import br.com.fafica.sisape.control.ControllerAgendas;
import br.com.fafica.sisape.control.ControllerClinica;
import br.com.fafica.sisape.control.ControllerUsuario;
import br.com.fafica.sisape.model.Clinica;

import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;

public class TelaUsuarioMarcarExame extends JFrame {

	private JPanel contentPane;

	/**
	 * Launch the application.
	 */
	public static void main(String[] args) {
		EventQueue.invokeLater(new Runnable() {
			public void run() {
				try {
					TelaUsuarioMarcarConsulta frame = new TelaUsuarioMarcarConsulta();
					frame.setVisible(true);
				} catch (Exception e) {
					e.printStackTrace();
				}
			}
		});
	}

	/**
	 * Create the frame.
	 */
	public TelaUsuarioMarcarExame() {
		setResizable(false);
		setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
		setBounds(100, 100, 270, 410);
		contentPane = new JPanel();
		contentPane.setBackground(new Color(255, 255, 255));
		contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
		setContentPane(contentPane);
		contentPane.setLayout(null);
		
		JLabel lblEscolhaSeuMdico = new JLabel("Qual sua Cl\u00EDnica?");
		lblEscolhaSeuMdico.setFont(new Font("Tahoma", Font.PLAIN, 12));
		lblEscolhaSeuMdico.setForeground(new Color(0, 0, 128));
		lblEscolhaSeuMdico.setBounds(10, 11, 118, 15);
		contentPane.add(lblEscolhaSeuMdico);
		
		final JComboBox comboClinica = new JComboBox();
		comboClinica.setBounds(10, 37, 244, 29);
		contentPane.add(comboClinica);
		ControllerClinica controlCli = new ControllerClinica();
		ArrayList listaClinicas = controlCli.listarClinicas();
		comboClinica.addItem("");
		Clinica c;
		for(int i =0; i < listaClinicas.size(); i++){
			c = (Clinica) listaClinicas.get(i);
			comboClinica.addItem(c.getNome());
		}
		
		JLabel lblAgendarConsulta = new JLabel("Datas Dispon\u00EDveis:");
		lblAgendarConsulta.setForeground(new Color(0, 0, 128));
		lblAgendarConsulta.setFont(new Font("Tahoma", Font.PLAIN, 12));
		lblAgendarConsulta.setBounds(10, 87, 105, 15);
		contentPane.add(lblAgendarConsulta);
		
		final JComboBox comboData = new JComboBox();
		comboData.setBounds(10, 113, 244, 29);
		contentPane.add(comboData);
		comboData.addItem("");
		ControllerAgendas controleData = new ControllerAgendas();
		ArrayList listaDatas = controleData.carregaDia();
		String dia;
		for(int i=0; i < listaDatas.size(); i++){
			dia = (String) listaDatas.get(i);
			comboData.addItem(dia);
		}
		
		JLabel lblHora = new JLabel("Hora do Exame:");
		lblHora.setForeground(new Color(0, 0, 128));
		lblHora.setFont(new Font("Tahoma", Font.PLAIN, 12));
		lblHora.setBounds(10, 163, 105, 15);
		contentPane.add(lblHora);
		
		final JComboBox comboHora = new JComboBox();
		comboHora.setBounds(10, 189, 244, 29);
		contentPane.add(comboHora);
		comboHora.addItem("");
		ControllerAgendas controleHora = new ControllerAgendas();
		ArrayList listaHora = controleHora.carregaHora();
		String hora;
		for(int i=0; i < listaHora.size(); i++){
			hora = (String) listaHora.get(i);
			comboHora.addItem(hora);
		}
		
		JButton btnMarcar = new JButton("Marcar");
		btnMarcar.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				
				String clinica = (String) comboClinica.getSelectedItem();
				String data = (String) comboData.getSelectedItem();
				String hora = (String) comboHora.getSelectedItem();
				
				ControllerAgendas control = new ControllerAgendas();
				control.inserirAgendaExame(data, hora, ControllerUsuario.userLogado, clinica);
				dispose();
			}
		});
		btnMarcar.setForeground(new Color(0, 0, 128));
		btnMarcar.setFont(new Font("Tahoma", Font.PLAIN, 14));
		btnMarcar.setBounds(85, 283, 89, 35);
		contentPane.add(btnMarcar);
	}
}